<template>
    <div class="cont-detail">
        <div id="detail" v-loading="loading">
            <el-form :rules="rules" :label-position="labePosition" label-width="85px" size="mini" style="height: 92vh">
                <el-row class="row-style">
                    <el-card>
                        <el-row>
                            <el-form-item label="风险说明">
                                <el-input v-model="entryControl.entryName" :disabled="true" />
                            </el-form-item>
                        </el-row>
                        <el-row>
                            <el-col :span="6">
                                <el-form-item label="风险类型">
                                    <el-select
                                        placeholder="请选择"
                                        style="width: 100%"
                                        :disabled="true"
                                        @change="handleChang('entryType', entryControl.entryType)"
                                        v-model="entryControl.entryType"
                                    >
                                        <el-option
                                            v-for="itme in entryType"
                                            :key="itme.dictKey"
                                            :label="itme.dictKey + ' ' + itme.dictKeyName"
                                            :value="itme.dictKey"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="启用状态">
                                    <el-switch v-model="entryControl.entryStatusValid" :disabled="true" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="作用范围">
                                    <el-checkbox-group v-model="entryControl.riskCalTypes" :disabled="true">
                                        <el-checkbox label="1">指令 </el-checkbox>
                                        <el-checkbox label="0" :disabled="entryControl.entryType === '3'">静态</el-checkbox>
                                    </el-checkbox-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="优先级">
                                    <el-input-number controls-position="right" v-model="entryControl.level" :disabled="true" :min="1" :max="10" />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="6">
                                <el-form-item label="生效日期">
                                    <el-date-picker
                                        type="date"
                                        format="yyyyMMdd"
                                        value-format="yyyyMMdd"
                                        placeholder="选择日期"
                                        v-model="entryControl.beginDate"
                                        style="width: 100%"
                                        :disabled="true"
                                    />
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="失效日期">
                                    <el-date-picker
                                        type="date"
                                        placeholder="选择日期"
                                        format="yyyyMMdd"
                                        value-format="yyyyMMdd"
                                        v-model="entryControl.endDate"
                                        style="width: 60%"
                                        :disabled="true"
                                    />
                                    <el-popover placement="bottom" width="260" v-model="visible">
                                        <div style="text-align: right; margin: 0; padding: 5px">
                                            <div class="detail-col">
                                                <el-row style="margintop: 10px">
                                                    <el-col :span="6"> 周期类型 </el-col>
                                                    <el-col :span="17">
                                                        <el-select
                                                            v-model="entryControl.controlValue"
                                                            clearable
                                                            @change="handleBaseInfo(entryControl.controlValue)"
                                                        >
                                                            <el-option
                                                                v-for="itme in types"
                                                                :key="itme.dictKey"
                                                                :label="itme.dictKeyName"
                                                                :value="itme.dictKey"
                                                            ></el-option>
                                                        </el-select>
                                                    </el-col>
                                                </el-row>
                                                <el-row style="margintop: 10px">
                                                    <el-col :span="6"> 控制值 </el-col>
                                                    <el-col :span="17">
                                                        <el-select
                                                            v-model="entryControl.dateType"
                                                            @change="changeDate(entryControl.dateType)"
                                                            clearable
                                                        >
                                                            <el-option
                                                                v-for="itme in typeDetails"
                                                                :key="itme.dictKey"
                                                                :label="itme.dictKeyName"
                                                                :value="itme.dictKey"
                                                            ></el-option>
                                                        </el-select>
                                                    </el-col>
                                                </el-row>
                                                <el-row style="margintop: 10px">
                                                    <el-col :span="6"> 是否循环 </el-col>
                                                    <el-col :span="2">
                                                        <el-switch v-model="entryControl.isCycle" active-value="1" inactive-value="0"> </el-switch>
                                                        <!-- <el-checkbox v-model="entryControl.isCycle" label="1" /> -->
                                                    </el-col>
                                                </el-row>
                                            </div>
                                            <el-button type="primary" size="mini" @click="visible = false">确定</el-button>
                                        </div>
                                        <el-button size="mini" slot="reference" type="primary" :disabled="true">更多</el-button>
                                    </el-popover>
                                </el-form-item>
                            </el-col>
                            <el-col :span="4">
                                <el-form-item label="条目标签">
                                    <el-select
                                        placeholder="请选择"
                                        style="width:100%"
                                        multiple
                                        filterable
                                        disabled
                                        v-model="entryControl.entryTagIds"
                                        :title="entryControl.entryTagIds"
                                    >
                                        <el-option
                                            v-for="itme in entryTagIdList"
                                            :key="itme.dictKey"
                                            :label="itme.dictKey + ' ' + itme.dictKeyName"
                                            :value="itme.dictKey"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="4">
                                <el-form-item label="风险等级">
                                    <el-select placeholder="请选择" v-model="entryControl.controlGrade" :disabled="true" style="width: 100%">
                                        <el-option
                                            v-for="itme in controlGrade"
                                            :key="itme.dictKey"
                                            :label="itme.dictKey + ' ' + itme.dictKeyName"
                                            :value="itme.dictKey"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="4">
                                <el-form-item label="比较方向">
                                    <el-select placeholder="请选择" v-model="entryControl.compareType" style="width: 100%" :disabled="true">
                                        <el-option
                                            v-for="itme in compareDirection"
                                            :key="itme.dictKey"
                                            :label="itme.dictKey + ' ' + itme.dictKeyName"
                                            :value="itme.dictKey"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-card>
                </el-row>
                <el-row class="row-style card-box">
                    <el-col :span="12">
                        <el-card class="card-left">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="账户层次">
                                        <el-select
                                            placeholder="请选择"
                                            v-model="entryControl.originalAccountId"
                                            style="width: 100%"
                                            :disabled="true"
                                            @change="changOriginalAccoutId()"
                                        >
                                            <el-option
                                                v-for="itme in originalAccountType"
                                                :key="itme.dictKey"
                                                :label="itme.dictKey + ' ' + itme.dictKeyName"
                                                :value="itme.dictKey"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="控制类型">
                                        <el-select
                                            placeholder="请选择"
                                            v-model="entryControl.accountControlType"
                                            :disabled="true"
                                            style="width: 100%"
                                        >
                                            <p>
                                                <el-option
                                                    v-for="itme in accountControlType_0"
                                                    :key="itme.dictKey"
                                                    :label="itme.dictKey + ' ' + itme.dictKeyName"
                                                    :value="itme.dictKey"
                                                ></el-option>
                                            </p>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="控制账户" v-if="entryControl.originalAccountId == '0'">
                                        <el-select
                                            placeholder="请选择"
                                            v-model="entryControl.accountControlValue"
                                            multiple
                                            filterable
                                            collapse-tags
                                            style="width: 100%"
                                            @change="changAccountControlValue(entryControl.accountControlValue)"
                                        >
                                            <el-option label="-1 选择全部" value="-1" :disabled="true"></el-option>
                                            <el-option
                                                :disabled="true"
                                                v-for="itme in fundInfo"
                                                :key="itme.value"
                                                :label="itme.label"
                                                :value="itme.value"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="账户组" v-else>
                                        <el-select
                                            placeholder="请选择"
                                            v-model="entryControl.accountControlValue"
                                            multiple
                                            filterable
                                            collapse-tags
                                            style="width: 100%"
                                        >
                                            <!-- <el-option label="选择全部" value="-1"></el-option> -->
                                            <el-option
                                                :disabled="true"
                                                v-for="itme in fundGroup"
                                                :key="itme.value"
                                                :label="itme.label"
                                                :value="itme.value"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="排除账户">
                                        <el-select
                                            placeholder="请选择"
                                            v-model="entryControl.accountDebarValue"
                                            multiple
                                            filterable
                                            collapse-tags
                                            style="width: 100%"
                                        >
                                            <el-option
                                                v-for="itme in fundInfos"
                                                :key="itme.value"
                                                :label="itme.label"
                                                :disabled="true"
                                                :value="itme.value"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="排除账户组">
                                        <el-select
                                            placeholder="请选择"
                                            multiple
                                            filterable
                                            collapse-tags
                                            v-model="entryControl.accountGroupDebarValue"
                                            style="width: 100%"
                                        >
                                            <el-option
                                                :disabled="true"
                                                v-for="itme in fundGroup"
                                                :key="itme.value"
                                                :label="itme.label"
                                                :value="itme.value"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-card>
                    </el-col>
                    <el-col :span="12">
                        <el-card class="card-right">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="控制值1">
                                        <el-input-number
                                            controls-position="right"
                                            :disabled="true"
                                            v-model="entryControl.thresholdValue1"
                                            class="right-inputs"
                                        />
                                        <el-select class="select-style" clearable v-model="entryControl.unit" :disabled="true" placeholder="无">
                                            <el-option
                                                v-for="item in unitFilter[this.entryControl.entryType]"
                                                :key="item"
                                                :label="item"
                                                :value="item"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="触警操作1">
                                        <el-select
                                            v-model="entryControl.thresholdType1"
                                            :disabled="true"
                                            style="widht: 100%"
                                            clearable
                                            @change="changeThresholdType('1')"
                                        >
                                            <el-option
                                                v-for="itme in thresholdType"
                                                :key="itme.dictKey"
                                                :label="itme.dictKey + ' ' + itme.dictKeyName"
                                                :value="itme.dictKey"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="控制值2">
                                        <el-input-number
                                            controls-position="right"
                                            :disabled="true"
                                            v-model="entryControl.thresholdValue2"
                                            class="right-inputs"
                                        />
                                        <el-select class="select-style" clearable v-model="entryControl.unit" :disabled="true" placeholder="无">
                                            <el-option
                                                v-for="item in unitFilter[this.entryControl.entryType] || ['无']"
                                                :key="item"
                                                :label="item"
                                                :value="item"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="触警操作2">
                                        <el-select
                                            :disabled="true"
                                            v-model="entryControl.thresholdType2"
                                            style="widht: 100%"
                                            clearable
                                            @change="changThresholdType2()"
                                        >
                                            <el-option
                                                v-for="itme in thresholdType"
                                                :key="itme.dictKey"
                                                :disabled="itme.dictKey < entryControl.thresholdType1"
                                                :label="itme.dictKey + ' ' + itme.dictKeyName"
                                                :value="itme.dictKey"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="控制值3">
                                        <el-input-number
                                            controls-position="right"
                                            :disabled="true"
                                            v-model="entryControl.thresholdValue3"
                                            class="right-inputs"
                                        />
                                        <el-select class="select-style" clearable v-model="entryControl.unit" :disabled="true" placeholder="无">
                                            <el-option
                                                v-for="item in unitFilter[this.entryControl.entryType]"
                                                :key="item"
                                                :label="item"
                                                :value="item"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="触警操作3">
                                        <el-select clearable v-model="entryControl.thresholdType3" :disabled="true" style="widht: 100%">
                                            <el-option
                                                v-for="itme in thresholdType"
                                                :key="itme.dictKey"
                                                :disabled="itme.dictKey < entryControl.thresholdType2"
                                                :label="itme.dictKey + ' ' + itme.dictKeyName"
                                                :value="itme.dictKey"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-card>
                    </el-col>
                </el-row>
                <el-row class="row-style">
                    <el-card>
                        <el-tabs type="card" v-model="activeTab">
                            <el-tab-pane label="分支设置" name="branch">
                                <BranchSetting
                                    style="height: 258px"
                                    @set-branch-data="getBranchData"
                                    :riskEntryBranchList="riskEntryBranchList"
                                    :showData="true"
                                ></BranchSetting>
                            </el-tab-pane>
                            <el-tab-pane label="高级设置" name="high">
                                <HighSetting
                                    style="height: 258px"
                                    @set-high-data="getHighdata"
                                    :entryParamsList="entryParamsList"
                                    :fxType="entryControl.entryType"
                                    :accountControlType="entryControl.accountControlType"
                                    :showData="true"
                                ></HighSetting>
                            </el-tab-pane>

                            <el-tab-pane label="基金范围" name="fundScope">
                                <el-col :span="12">
                                    <BoundCfgSetting
                                        :stockBound="fundRangesList"
                                        investGroupType="0"
                                        operateType="edit"
                                        operatePanelHeight="210px"
                                        style="height:258px"
                                        :showData="true"
                                        @onHandleOperateOver="onHandleOperateOver"
                                    ></BoundCfgSetting>
                                    <!-- <BoundCfg0
                                        :stockBound="fundRangesList"
                                        investGroupType="0"
                                        operateType="edit"
                                        operatePanelHeight="210px"
                                        style="height: 258px"
                                        @onHandleOperateOver="onHandleOperateOver"
                                    ></BoundCfg0> -->
                                </el-col>
                            </el-tab-pane>
                            <el-tab-pane label="联合设置" name="unite">
                                <UniteSetting
                                    style="height: 258px"
                                    @set-unite-data="getUniteData"
                                    :joinRiskEntryControls="riskEntryControlRelation.joinRiskEntryControls"
                                    :showData="true"
                                ></UniteSetting>
                            </el-tab-pane>
                            <el-tab-pane label="互斥设置" name="mutex">
                                <MutexSetting
                                    style="height: 258px"
                                    @set-mutex-data="getMutexData"
                                    :mutualRiskEntryControls="riskEntryControlRelation.mutualRiskEntryControls"
                                    :showData="true"
                                ></MutexSetting>
                            </el-tab-pane>
                            <el-tab-pane
                                label="可投余量"
                                name="useMargin"
                                :disabled="entryControl.entryType === '3' || entryControl.entryType === '5'"
                            >
                                <UseMargin
                                    :branchData="branchData"
                                    @set-use-data="getUserData"
                                    :entryControl="entryControl"
                                    :riskEntryBranchs="riskEntryBranchs"
                                    :showData="true"
                                    style="height: 258px"
                                ></UseMargin>
                            </el-tab-pane>
                        </el-tabs>
                    </el-card>
                </el-row>
                <el-row class="row-style">
                    <el-card>
                        <div class="buts">
                            <el-button @click="cancelTable">取消</el-button>
                            <el-button
                                type="primary"
                                @click="submitData"
                                :disabled="sbmitdisabled"
                                v-if="itemData.type == 'add' || itemData.type == 'edit' || itemData.type == 'copy' || itemData.type == 'editCheck'"
                                >确认</el-button
                            >
                        </div>
                    </el-card>
                </el-row>
            </el-form>
        </div>
    </div>
</template>
<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
import DictionConstUtil, { FNFundGroup, SGU_CACHE } from '@/utils/diction-const-util';
import { mixins } from 'vue-class-component';
import Control from '@/utils/risk-setting';
import BranchSetting from '../item-setting/branch-setting.vue';
import HighSetting from '../item-setting/high-setting.vue';
import FundScope from '../item-setting/fund-scope.vue';
import UniteSetting from '../item-setting/unite-setting.vue';
import MutexSetting from '../item-setting/mutex-setting.vue';
import UseMargin from '../item-setting/use-margin.vue';
import RiskEmitter from '@/common/mixis/risk-emitter.vue';
import BoundCfg0 from '@/pages/baseparam/fund-group-setting/BoundCfg0.vue';
import BoundCfgSetting from '@/pages/baseparam/fund-group-setting/BoundCfgSetting.vue';

@Component({
    name: 'ItemHistoryDetail',
    components: {
        BranchSetting,
        HighSetting,
        BoundCfgSetting,
        FundScope,
        UniteSetting,
        MutexSetting,
        UseMargin,
    },
})
export default class ItemHistoryDetail extends mixins(RiskEmitter) {
    @Prop() itemData: any;
    tabGroup: any[] = [
        {
            label: '分支设置',
            type: 'branch',
        },
        {
            label: '高级设置',
            type: 'high',
        },
        {
            label: '基金范围',
            type: 'fundScope',
        },
        {
            label: '联合设置',
            type: 'unite',
        },
        {
            label: '互斥设置',
            type: 'mutex',
        },
        {
            label: '可投余量',
            type: 'useMargin',
        },
    ];
    types: any[] = [
        { dictKey: 'month', dictKeyName: '月度' },
        { dictKey: 'season', dictKeyName: '季度' },
        { dictKey: 'year', dictKeyName: '年度' },
    ];
    typeDetails: any[] = [];
    months: any[] = [
        { dictKey: '1', dictKeyName: '一月' },
        { dictKey: '2', dictKeyName: '二月' },
        { dictKey: '3', dictKeyName: '三月' },
        { dictKey: '4', dictKeyName: '四月' },
        { dictKey: '5', dictKeyName: '五月' },
        { dictKey: '6', dictKeyName: '六月' },
        { dictKey: '7', dictKeyName: '七月' },
        { dictKey: '8', dictKeyName: '八月' },
        { dictKey: '9', dictKeyName: '九月' },
        { dictKey: '10', dictKeyName: '十月' },
        { dictKey: '11', dictKeyName: '十一月' },
        { dictKey: '12', dictKeyName: '十二月' },
    ];
    seasons: any[] = [
        { dictKey: '1', dictKeyName: '第一季度' },
        { dictKey: '2', dictKeyName: '第二季度' },
        { dictKey: '3', dictKeyName: '第三季度' },
        { dictKey: '4', dictKeyName: '第四季度' },
    ];

    years: any[] = [
        { dictKey: '1', dictKeyName: '上半年' },
        { dictKey: '2', dictKeyName: '下半年' },
        { dictKey: '3', dictKeyName: '年' },
    ];
    type: any = '';
    value1: any = null;
    loading: boolean = false;
    visible: boolean = false;
    activeTab: string = 'branch';
    checkList: any = [];
    entryTagIdList: any = [];
    entryControl: any = {
        entryName: '', // 风险说明
        entryType: '0', // 风险类型
        entryStatusValid: true, // 启用状态
        level: 5, // 优先级
        entryTagIds: [], // 条目标签
        beginDate: '', // 生效日期
        endDate: '', // 失效日期
        controlGrade: '0', // 风险等级
        originalAccountId: '0', // 账户层次
        accountControlType: '', // 控制类型
        accountControlValue: '', // '控制账户' : '账户组'
        accountDebarValue: '', // 排除账户
        accountGroupDebarValue: '', // 排除账户组
        thresholdType1: '3', // 触警操作1
        thresholdValue1: 0, // 阈值1
        thresholdType2: '', // 触警操作2
        thresholdValue2: '', // 阈值2
        thresholdType3: '', // 触警操作3
        thresholdValue3: '', // 阈值3
        compareType: '0', // 比较方向
        riskCalTypes: ['0', '1'], // 作用范围
        unit: '',
        isCycle: '0', // 是否循环
        dateType: '',
        controlValue: '',
        usableSubstitute: '',
    };
    riskEntryControlRelation: any = {
        joinRiskEntryControls: [], // 联合设置
        mutualRiskEntryControls: [], // 互斥设置
    };
    riskEntryBranchs: any[] = []; // 分支设置
    entryParams: any[] = []; // 高级设置
    fundRanges: any[] = []; // 范围配置

    entryType: any[] = []; // 风险类型数组
    controlGrade: any[] = []; // 风险等级数组
    compareDirection: any[] = []; // 比较方向数组
    originalAccountType: any[] = []; // 账户组数组
    // eslint-disable-next-line camelcase
    accountControlType_0: any[] = []; // 控制类型
    // eslint-disable-next-line camelcase
    accountControlType_1: any[] = [];
    thresholdType: any[] = []; // 触警操作
    unitFilter: any = []; // 操作值后面的选项
    fundInfo: any[] = []; // 基金信息
    fundInfos: any[] = [];
    fundGroup: any[] = []; // 基金组信息
    stockBound: any[] = []; // 范围属性组集合
    branchData: any[] = []; // 分支设置中分支数组

    riskEntryBranchList: any[] = [];
    entryParamsList: any[] = [];
    fundRangesList: any[] = [];
    joinRiskEntryControls: any[] = [];

    // 复核编辑
    postData: any = {
        entryControl: null,
        riskEntryControlRelation: null,
        riskEntryBranchs: null,
        entryParams: null,
        fundRanges: null,
        historyNo: null,
        modifyType: null,
        changeNo: null,
        serialNo: null,
    };
    sbmitdisabled: boolean = false;
    accountControlType0: any[] = [];
    Accountdisabled: boolean = false;
    AccountdisabledAll: boolean = false;

    created() {
        // 编辑请求数据
        // this.getEntryDetail();
    }

    async mounted() {
        this.entryType = DictionConstUtil.PojoToList(DictionConstUtil.EntryType);
        this.controlGrade = DictionConstUtil.PojoToList(DictionConstUtil.ControlGrade);
        // 风险等级
        // this.controlGrade = this.control.pojoTransFormList(this.control.ControlGrade)
        this.compareDirection = DictionConstUtil.PojoToList(DictionConstUtil.CompareDirection).filter(item =>
            ['5', '3'].includes(this.entryControl.entryType) ? item.dictKey === '6' : !['4', '5', '6'].includes(item.dictKey)
        );
        this.originalAccountType = DictionConstUtil.PojoToList(DictionConstUtil.OriginalAccountType);
        let AccountControlType = DictionConstUtil.PojoToList(DictionConstUtil.AccountControlType);
        this.accountControlType0 = AccountControlType.filter(item => ['0', '1', '4'].includes(item.dictKey));
        this.accountControlType_0 = this.accountControlType0.filter(
            item => (this.entryControl.entryType !== '3' && item.dictKey !== '4') || this.entryControl.entryType === '3'
        );
        let accountControlType1 = AccountControlType.filter(item => !['1', '4'].includes(item.dictKey));
        this.accountControlType_1 = accountControlType1.filter(
            item => (this.entryControl.entryType !== '3' && ['0', '2', '3'].includes(item.dictKey)) || this.entryControl.entryType === '3'
        );
        this.thresholdType = DictionConstUtil.PojoToList(DictionConstUtil.ThresholdType).filter(item => item.dictKey !== '4');
        this.unitFilter = DictionConstUtil.UnitFilter;
        let funds: any = await SGU_CACHE('FundInfo', '/fundInfo/list', []);
        let fundInfo = [];
        this.fundInfos = [];
        for (let i = 0; i < funds.length; i++) {
            fundInfo.push({ label: funds[i].fundCode + funds[i].fundNameSt, value: funds[i].fundCode });
            this.fundInfos.push({ label: funds[i].fundCode + funds[i].fundNameSt, value: funds[i].fundCode });
        }
        let pushData = {
            label: '全部选择',
            value: '-1',
        };
        this.fundInfo = fundInfo;
        let fundGroups = await FNFundGroup();
        let fundgroup = [];
        for (let i = 0; i < fundGroups.length; i++) {
            fundgroup.push({ label: fundGroups[i].fundGroupCode + fundGroups[i].fundGroupName, value: fundGroups[i].fundGroupCode });
        }
        this.fundGroup = fundgroup;
        this.getEntryDetail();
        this.getEntryTagled();
    }

    getEntryTagled() {
        this.$axios.get('/entryTag/queryAll').then(res => {
            this.entryTagIdList = res;
        });
    }

    // 监听账户层次
    changOriginalAccoutId() {
        this.entryControl.accountControlValue = '';
        if (this.entryControl.originalAccountId == '0') {
            this.accountControlType_0 = this.accountControlType0.filter(
                item => (this.entryControl.entryType !== '3' && item.dictKey !== '4') || this.entryControl.entryType === '3'
            );
        } else {
            this.accountControlType_0 = this.accountControlType_1;
        }
        this.entryControl.accountControlType = '0';
    }

    // 给组件传参
    handleChang(type: string, val: any) {
        if (type === 'entryType') {
            this.broadcast('HighSetting', 'addTables', val);
            this.broadcast('BranchSetting', 'setentryTypes', val);
            this.broadcast('UniteSetting', 'setentryTypes', val);
            this.broadcast('MutexSetting', 'setentryTypes', val);
        }
    }

    // 高级设置组件参数
    getHighdata(data: any) {
        this.entryParams = data;
    }

    // 分支设置中分支的回调
    getBranchData(data: any) {
        this.branchData = data;
        this.riskEntryBranchs = data;
    }

    // 可投余量的回调
    getUserData(data: any) {
        this.entryControl.usableSubstitute = data;
    }

    // 联合设置回调
    getUniteData(data: any) {
        this.riskEntryControlRelation.joinRiskEntryControls = data;
    }

    // 互斥设置回调
    getMutexData(data: any) {
        this.riskEntryControlRelation.mutualRiskEntryControls = data;
    }

    // 基金范围回调
    onHandleOperateOver(value: any): void {
        this.fundRanges = value;
    }

    /**
     * 改变日期类型
     */
    handleBaseInfo(value: any) {
        if (value === 'month') {
            this.type = 'month';
            this.typeDetails = this.months;
        } else if (value === 'season') {
            this.type = 'season';
            this.typeDetails = this.seasons;
        } else if (value === 'year') {
            this.type = 'year';
            this.typeDetails = this.years;
        } else {
            this.type = '0';
            this.typeDetails = [];
        }
    }

    /**
     * 改变控制值
     */
    changeDate(value: any): void {
        const year = new Date().getFullYear();
        const type = this.type;
        const date = new Date(year, value, 0);
        const days = date.getDate();
        var beginDate;
        var endDate;
        var type1: any = 0;
        this.value1 = value;
        if (type === 'month') {
            type1 = '1';
            if (parseInt(value) < 10 && parseInt(value) > 0) {
                beginDate = year + '0' + value + '01';
                endDate = year + '0' + value + days;
            } else if (parseInt(value) >= 10) {
                beginDate = year + value + '01';
                endDate = year + value + days;
            } else {
                beginDate = '';
                endDate = '';
            }
        } else if (type === 'season') {
            type1 = '2';
            if (value === '1') {
                beginDate = year + '0101';
                endDate = year + '0331';
            } else if (value === '2') {
                beginDate = year + '0401';
                endDate = year + '0630';
            } else if (value === '3') {
                beginDate = year + '0701';
                endDate = year + '0930';
            } else if (value === '4') {
                beginDate = year + '1001';
                endDate = year + '1231';
            } else {
                beginDate = '';
                endDate = '';
            }
        } else if (type === 'year') {
            type1 = '3';
            if (value === '1') {
                beginDate = year + '0101';
                endDate = year + '0630';
            } else if (value === '2') {
                beginDate = year + '0701';
                endDate = year + '1231';
            } else if (value === '3') {
                beginDate = year + '0101';
                endDate = year + '1231';
            } else {
                beginDate = '';
                endDate = '';
            }
        }
        this.entryControl.beginDate = beginDate;
        this.entryControl.endDate = endDate;
    }

    changeThresholdType(val: string) {
        if (val === '1') {
            this.entryControl.thresholdType2 = '';
            this.entryControl.thresholdType3 = '';
        }
    }

    // 提交
    async submitData() {
        this.sbmitdisabled = true;
        let entryParamsData = this.entryParams;
        // 处理数据格式 把值转为字符串
        for (let i = 0; i < entryParamsData.length; i++) {
            // eslint-disable-next-line no-mixed-operators
            if (
                entryParamsData[i].paramType === 'e' ||
                entryParamsData[i].paramType === '2' ||
                entryParamsData[i].paramType === '3' ||
                (entryParamsData[i].paramType === '4' && entryParamsData[i].paramValue)
            ) {
                entryParamsData[i].paramValue = entryParamsData[i].paramValue.toString();
            }
        }
        let data = {
            entryControl: this.entryControl,
            riskEntryControlRelation: this.riskEntryControlRelation,
            riskEntryBranchs: this.riskEntryBranchs,
            entryParams: this.entryParams,
            fundRanges: this.fundRanges,
        };
        if (data.entryControl.thresholdType2 === '') {
            data.entryControl.thresholdValue2 = '';
        }
        if (data.entryControl.thresholdType3 === '') {
            data.entryControl.thresholdValue3 = '';
        }
        let verify = await Control.verifyItemDetailParam(data);
        if (verify !== 'SUCCESS') {
            this.sbmitdisabled = false;
            this.yh_message_error(verify);
            return;
        }
        if (this.itemData.type === 'add') {
            this.loading = true;
            this.$axios
                .post('/entry/insert/entryControl', data)
                .then(res => {
                    this.loading = false;
                    this.yh_message_success('操作成功');
                    this.cancelTable();
                })
                .catch(() => {
                    this.loading = false;
                    this.sbmitdisabled = false;
                });
        } else if (this.itemData.type === 'copy') {
            this.loading = true;
            this.$axios
                .post('/entry/insert/entryControl', data)
                .then(res => {
                    this.loading = false;
                    this.yh_message_success('操作成功');
                    this.cancelTable();
                })
                .catch(() => {
                    this.loading = false;
                    this.sbmitdisabled = false;
                });
        } else {
            this.$confirm('确定修改吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    if (this.itemData.type === 'edit') {
                        this.loading = true;
                        this.$axios
                            .post('/entry/update/entryControl', data)
                            .then(res => {
                                this.loading = false;
                                this.yh_message_success('操作成功');
                                this.cancelTable();
                            })
                            .catch(() => {
                                this.loading = false;
                                this.sbmitdisabled = false;
                            });
                    } else if (this.itemData.type === 'editCheck') {
                        this.postData.entryControl = this.entryControl;
                        this.postData.riskEntryControlRelation = this.riskEntryControlRelation;
                        this.postData.riskEntryBranchs = this.riskEntryBranchs;
                        this.postData.entryParams = this.entryParams;
                        this.postData.fundRanges = this.fundRanges;
                        this.loading = true;
                        this.$axios
                            .post('/entry/update/check/entryControl', this.postData)
                            .then(res => {
                                this.loading = false;
                                this.yh_message_success('操作成功');
                                this.cancelTable();
                            })
                            .catch(() => {
                                this.loading = false;
                                this.sbmitdisabled = false;
                            });
                    }
                })
                .catch(() => {
                    this.sbmitdisabled = false;
                    this.yh_message_info('已取消删除');
                    // this.$message({
                    //     type: 'info',
                    //     message: '已取消删除',
                    // });
                });
        }
    }

    // 关闭页面
    cancelTable() {
        this.$emit('opne-table', this.itemData.title);
    }

    changAccountControlValue(val: any) {
        let a = val.find((item: any) => {
            return item == '-1';
        });
        if (val.length == 0) {
            this.Accountdisabled = false;
            this.AccountdisabledAll = false;
        } else if (a == '-1') {
            this.Accountdisabled = false;
            this.AccountdisabledAll = true;
        } else {
            this.Accountdisabled = true;
            this.AccountdisabledAll = false;
        }
    }

    /**
     *
     *
     * 获取数据
     */
    getEntryDetail() {
        if (this.itemData.type === 'add') {
            return;
        } else if (this.itemData.type === 'editCheck' || this.itemData.type === 'lookCheck' || this.itemData.type === 'check-look') {
            this.loading = true;
            this.$axios
                .get(
                    '/entry/checkDetail/' +
                        this.itemData.content.entryCode +
                        '/' +
                        this.itemData.content.serialNo +
                        '/' +
                        this.itemData.content.changeNo
                )
                .then((res: any) => {
                    this.loading = false;
                    res.entryControl.originalAccountId = res.entryControl.originalAccountId.toString();
                    if (res.entryControl.beginDate == 0) {
                        res.entryControl.beginDate = '';
                    } else {
                        res.entryControl.beginDate = res.entryControl.beginDate.toString();
                    }
                    if (res.entryControl.endDate == 0) {
                        res.entryControl.endDate = '';
                    } else {
                        res.entryControl.endDate = res.entryControl.endDate.toString();
                    }
                    this.entryControl = res.entryControl;

                    this.riskEntryControlRelation = res.riskEntryControlRelation;
                    if (res.entryControl.controlValue) {
                        if (res.entryControl.controlValue == '0') {
                            this.entryControl.controlValue = '';
                        } else {
                            this.entryControl.controlValue = res.entryControl.controlValue.toString();
                            this.handleBaseInfo(this.entryControl.controlValue);
                        }
                    }
                    if (res.entryControl.dateType) {
                        if (res.entryControl.dateType == '0') {
                            this.entryControl.dateType = '';
                        } else {
                            this.entryControl.dateType = res.entryControl.dateType.toString();
                        }
                    }
                    this.riskEntryBranchList = res.riskEntryBranchs;
                    this.entryParamsList = res.entryParams;
                    this.fundRangesList = res.fundRanges;
                    this.postData.changeNo = res.changeNo;
                    this.postData.historyNo = res.historyNo;
                    this.postData.modifyType = res.modifyType;
                    this.postData.serialNo = res.serialNo;
                });
        } else if (this.itemData.type === 'look' || this.itemData.type === 'edit' || this.itemData.type === 'copy') {
            this.loading = true;
            this.$axios.get('/entry/history/detail/' + this.itemData.content + '/' + this.itemData.historyNo).then((res: any) => {
                this.loading = false;
                res.entryControl.originalAccountId = res.entryControl.originalAccountId.toString();
                if (res.entryControl.beginDate == 0) {
                    res.entryControl.beginDate = '';
                } else {
                    res.entryControl.beginDate = res.entryControl.beginDate.toString();
                }
                if (res.entryControl.endDate == 0) {
                    res.entryControl.endDate = '';
                } else {
                    res.entryControl.endDate = res.entryControl.endDate.toString();
                }
                this.entryControl = res.entryControl;
                if (res.entryControl.controlValue) {
                    if (res.entryControl.controlValue == '0') {
                        this.entryControl.controlValue = '';
                    } else {
                        this.entryControl.controlValue = res.entryControl.controlValue.toString();
                        this.handleBaseInfo(this.entryControl.controlValue);
                    }
                }
                if (res.entryControl.dateType) {
                    if (res.entryControl.dateType == '0') {
                        this.entryControl.dateType = '';
                    } else {
                        this.entryControl.dateType = res.entryControl.dateType.toString();
                    }
                }
                this.riskEntryControlRelation = res.riskEntryControlRelation;
                this.riskEntryBranchList = res.riskEntryBranchs;
                this.entryParamsList = res.entryParams;
                this.fundRangesList = res.fundRanges;
            });
        }
    }
}
</script>
<style lang="scss" scoped>
.cont-detail {
    color: #222;
    width: 100vw;
    overflow: auto;

    #detail .row-style {
        margin-bottom: 10px;
        min-width: 1200px;
        overflow: auto;

        & /deep/ .el-card__body {
            padding: 5px;
        }

        & /deep/ .el-form-item--mini.el-form-item,
        .el-form-item--small.el-form-item {
            margin-bottom: 5px;
        }

        .card-box .card-left {
            margin-right: 5px;
        }

        .card-box .card-right {
            margin-right: 5px;
        }

        .card-right .right-inputs {
            width: 140px;
        }

        .card-right .select-style {
            width: 20%;
            display: inline-block;
        }

        .select-style /deep/ .el-input__icon {
            display: none;
        }

        .select-style /deep/ .el-input--suffix .el-input__inner {
            padding: 0 10px;
        }

        .buts {
            display: inline;
            float: right;
        }

        .detail-col {
            padding: 10px;
            .col-row {
                padding-top: 10px;
            }
        }
    }

    & /deep/ .el-button--mini,
    .el-button--mini.is-round {
        padding: 6px 15px;
    }

    & /deep/ .el-select__tags {
        flex-wrap: nowrap;
        overflow: hidden;
    }
}
/deep/ .el-form-item--mini .el-form-item__label {
    color: #222;
}
</style>
